package com.list88zhu.android.sunflower.jetpack;

import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.list88zhu.android.sunflower.R;
import com.list88zhu.android.sunflower.jetpack.paging.PlantAdapter;
import com.list88zhu.android.sunflower.jetpack.paging.PlantViewModel;

/**
 * <pre><code>
 *
 *  </code></pre>
 *
 * @author zhuyingming@qmtv.com
 * @date 2018/8/26
 */
public class PlantQueryActivity extends AppCompatActivity {

    private PlantViewModel plantViewModel;

    private RecyclerView recyclerView;
    private PlantAdapter plantAdapter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_plan_query);

        recyclerView = findViewById(R.id.recyclerView);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
        dividerItemDecoration.setDrawable(ContextCompat.getDrawable(this, R.drawable.divider));
        recyclerView.addItemDecoration(dividerItemDecoration);

        plantAdapter = new PlantAdapter();
        recyclerView.setAdapter(plantAdapter);

        plantViewModel = ViewModelProviders.of(this).get(PlantViewModel.class);
        plantViewModel.getPlantPagedList().observe(this,
            pagedList -> plantAdapter.submitList(pagedList));
    }
}
